package com.dao.auth;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.common.base.BaseSqlMapDAO;
import com.model.auth.Role;

public class RoleDao extends BaseSqlMapDAO{
	
	
	@SuppressWarnings("unchecked")
	public List<Role> getRolePageInfo(int pageNO,int pageSize) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("offset", (pageNO-1)<0?0:(pageNO-1)*pageSize);
		map.put("max", pageSize);
		return this.getSqlMapClientTemplate().queryForList("mrole.getRolePageInfo", map);
	}
	
	
	
	public int getRoleConunt()throws Exception{
		
		return Integer.valueOf(this.getSqlMapClientTemplate().queryForObject("mrole.getRoleConunt").toString());
	}
	
	
	public Role getRoleById(int id) throws Exception{
		
		
		return (Role) this.getSqlMapClientTemplate().queryForObject("mrole.getRoleById",id);
	}
	
	
	public boolean delRoleById(int id) throws Exception{
		
		return this.getSqlMapClientTemplate().delete("mrole.delRoleById",id)>0;
	}
	
	
	public boolean insertRole(Role role) throws Exception{
		
		
		return this.getSqlMapClientTemplate().insert("mrole.insertRole", role)!=null;
	}
	
	
	public boolean updateRole(Role role) throws Exception{
		
		
		return this.getSqlMapClientTemplate().update("mrole.updateRole", role)>0;
	}
	
	@SuppressWarnings("unchecked")
	public List<Role> getAllRole() throws Exception{
		
		return this.getSqlMapClientTemplate().queryForList("mrole.getAllRole");
	}
}
